﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public class ConquerCommand
    {
        public static void Parse(GameClient Client, string From, string To, string Msg)
        {
            try
            {
                if (!Client.Entity.Name.StartsWith("[GM]"))
                    return;
                string[] args = Msg.Split(' ');
                args[0] = args[0].ToLower();

                switch (args[0])
                {
                    case "@item": // @item id plus bless enchant s1 s2
                        {
                            IConquerItem item = new ItemDataPacket(true);
                            item.UID = ItemDataPacket.NextItemUID;
                            item.ID = uint.Parse(args[1]);
                            if (args.Length > 2)
                            {
                                item.Plus = byte.Parse(args[2]);
                                if (args.Length > 3)
                                {
                                    item.Bless = byte.Parse(args[3]);
                                    if (args.Length > 4)
                                    {
                                        item.Enchant = byte.Parse(args[4]);
                                        if (args.Length > 5)
                                        {
                                            item.SocketOne = byte.Parse(args[5]);
                                            if (args.Length > 6)
                                            {
                                                item.SocketTwo = byte.Parse(args[6]);
                                            }
                                        }
                                    }
                                }
                            }
                            Client.AddInventory(item);
                            break;
                        }
                    case "@quit":
                    case "@dc":
                    case "@disconnect":
                    case "@exit":
                        {
                            Client.Socket.Disconnect();
                            break;
                        }
                    case "@spell":
                    case "@skill": // @skill id lvl
                        {
                            Client.LearnSpell(ushort.Parse(args[1]), ushort.Parse(args[2]));
                            break;
                        }
                    case "@prof": // @prof id lvl
                        {
                            Client.LearnProf(ushort.Parse(args[1]), ushort.Parse(args[2]));
                            break;
                        }
                    case "@tp": // @tp mapID x y
                        {
                            Client.Teleport(ushort.Parse(args[1]), ushort.Parse(args[2]), ushort.Parse(args[3]));
                            break;
                        }
                    case "@goto":
                        {
                            switch (args[1].ToLower())
                            {
                                case "tc":
                                    Client.Teleport(1002, 431, 379);
                                    break;
                                case "pc":
                                    Client.Teleport(1011, 190, 271);
                                    break;
                                case "am":
                                    Client.Teleport(1020, 567, 576);
                                    break;
                                case "dc":
                                    Client.Teleport(1000, 500, 650);
                                    break;
                                case "bi":
                                    Client.Teleport(1015, 723, 573);
                                    break;
                                case "market":
                                case "m":
                                    Client.Teleport(1036, 200, 200);
                                    break;
                                case "arena":
                                case "a":
                                    Client.Teleport(1005, 52, 69);
                                    break;
                            }
                            break;
                        }
                    case "@cps":
                        {
                            Client.ConquerPoints += int.Parse(args[1]);
                            break;
                        }
                    case "@gold":
                    case "@money":
                        {
                            Client.ConquerPoints += int.Parse(args[1]);
                            break;
                        }
                    case "@heal":
                        {
                            Client.Entity.Hitpoints = Client.Entity.MaxHitpoints;
                            break;
                        }
                }
            }
            catch (Exception e)
            {
                Client.Send(new MessagePacket("[Command Error] " + e.Message, 0x00FF0000, MessagePacket.TopLeft));
            }
        }
    }
}
